package cn.mumzone.pos.ui.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import cn.mumzone.basic.adapter.rv.CommonAdapter;
import cn.mumzone.basic.adapter.rv.ViewHolder;
import cn.mumzone.basic.util.AppDateUtil;
import cn.mumzone.basic.util.StringUtils;
import cn.mumzone.pos.R;
import cn.mumzone.pos.model.TransactionRecordEntity;
import cn.mumzone.pos.util.BillUtil;

/**
 * Created by qiuzhenhuan on 2019/8/1.
 */

public class ADA_TransactionRecord extends CommonAdapter<TransactionRecordEntity> {

    public ADA_TransactionRecord(Context context) {
        super(context);
    }

    @Override
    protected int itemLayoutId() {
        return R.layout.item_transaction_record;
    }

    @Override
    protected void convert(ViewHolder holder, TransactionRecordEntity entity, int position) {

        TextView tvDay = holder.getView(R.id.tv_day);
        TextView tvTransactionType = holder.getView(R.id.tv_transaction_type);
        TextView tvAmount = holder.getView(R.id.tv_amount);
        TextView tvBalance = holder.getView(R.id.tv_balance);
        TextView tvPayType = holder.getView(R.id.tv_pay_type);
        TextView tvCode = holder.getView(R.id.tv_code);


        tvDay.setText(AppDateUtil.getFriendlyDateTime(entity.getCreateTime(), AppDateUtil.HH_MM_SS, AppDateUtil.YYYY_MM_DD_HH_MM_SS));
        String tradeType = "";
        if ("0".equals(entity.getTradeType())) {//交易类型（0-充值，2-提现，3-转账 4-余额消费）
            tradeType = "充值";
        } else if ("2".equals(entity.getTradeType())) {
            tradeType = "提现";
        } else if ("3".equals(entity.getTradeType())) {
            tradeType = "转账";
        } else if ("4".equals(entity.getTradeType())) {
            tradeType = "消费";
        }else if ("5".equals(entity.getTradeType())) {
            tradeType = "退款";
        }

        String amount = String.format("%s%s", "0".equals(entity.getTradeType()) || "5".equals(entity.getTradeType())
                ? "+" : "-", StringUtils.getFormattedMoneyWithUnit(entity.getAmount()));
        tvTransactionType.setText(tradeType);
        tvAmount.setText(amount);
        tvBalance.setText(StringUtils.getFormattedMoneyWithUnit(entity.getBalance()));
        tvPayType.setText("0".equals(entity.getTradeType())
                ? BillUtil.getSimplePayType(entity.getPayType()) : "--");
        tvCode.setText(StringUtils.get(entity.getOrderCode()));


    }
}
